package com.immunology.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;

import com.immunology.logic.TextFieldConvertor;

public class RegistrationPostService {

	private Map<String, String> parameters = new HashMap<String, String>();

	public Map<String, String> getParameters() {
		return parameters;
	}

	@SuppressWarnings("unchecked")
	public void uploadRegistrationData(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Map<String, String[]> param = new HashMap<String, String[]>();
		param = request.getParameterMap();
		Iterator<String> iterator = param.keySet().iterator();
		while (iterator.hasNext()) {
			String paramName = iterator.next();
			String paramValue = request.getParameter(paramName);
			parameters.put(paramName, paramValue);
		}
	}

	private void addParameter(FileItem item) {
		TextFieldConvertor convertor = new TextFieldConvertor();
		String itemConverted = convertor.convertToUTF(item.getString());
		parameters.put(item.getFieldName(), itemConverted);
	}

}
